import java.util.HashSet;
import java.util.Set;

public class leetcode3_无重复字符的最长子串 {
    public static void main(String[] args) {
        Solution8 solution8 = new Solution8();
        System.out.println(solution8.lengthOfLongestSubstring("abcabcbb"));

    }
}


class Solution8 {
    public int lengthOfLongestSubstring(String s) {
        int slow = 0, fast;
        int _max = 0;
        Set<Character> set = new HashSet<>();
        for (fast = 0; fast < s.length(); fast++) {
            while (set.contains(s.charAt(fast))) {
                set.remove(s.charAt(slow++));
            }
            set.add(s.charAt(fast));
//            System.out.println(String.format("%s %d %d", set, fast, slow));
            if (set.size() > _max) {
                _max = set.size();
            }
        }
        return _max;
    }

    ;
}